package com.briup.app02.web.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.briup.app02.bean.BaseUser;
import com.briup.app02.bean.BaseUserRole;
import com.briup.app02.bean.extend.BaseUserExtend;
import com.briup.app02.bean.extend.BaseUserRoleExtend;
import com.briup.app02.service.IBaseUserService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;
import com.briup.app02.bean.extend.UserExtend;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@RestController
@RequestMapping("/baseuser")
@Api(description = "用户管理")
public class BaseUserController {
	
	@Autowired
	private IBaseUserService baseuserService;
	
	
	@GetMapping("query")
	@ApiOperation("查询所有用户信息")
	public Message query(String username,String status){
		List<BaseUser> list = baseuserService.query(username, status);
		return MessageUtil.success(list);
	}
	
	@GetMapping("queryCascade")
	@ApiOperation("级联查询所有用户信息")
	
	public Message queryCascade(String username,String status,String role){
		List<UserExtend> list = baseuserService.CascadeQuery(username,status,role);
		return MessageUtil.success(list);
	}
	
	@GetMapping("findById")
	@ApiOperation("根据id查询用户详情")
	@ApiImplicitParam(name ="id",value = "用户id",dataType = "long",paramType = "query",required = true)
	public Message findById(long id) {
		BaseUser baseuser = baseuserService.findUserDetailsById(id);
		return MessageUtil.success(baseuser);
	}
	
	@PostMapping("saveOrUpdate")
	@ApiOperation(value="保存或更新",notes = "id为空是保存否则是更新")
	public Message saveOrUpdate(BaseUser baseuser) {
		baseuserService.SaveOrUpdate(baseuser);
		return MessageUtil.success("操作成功");
	}
	@GetMapping("deleteById")
	@ApiOperation("根据id删除用户信息")
	@ApiImplicitParam(name="id",value = "用户id",dataType = "long",paramType = "query",required = true)
	public Message deleteById(long id) {
		baseuserService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
	
	@PostMapping("alterUserface")
	@ApiOperation(value="修改用户头像")
	public Message alterUserface(Long id,String userface) {
		baseuserService.alterUserface(id, userface);
		return MessageUtil.success("操作成功");
	}
	
	
	@ApiOperation(value = "分页查询用户信息")
//      @ApiImplicitParams({
//    	@ApiImplicitParam(name="pageIndex",value = "页码",paramType = "query",required = true),
//    	@ApiImplicitParam(name="pageSize",value = "每页记录数",paramType = "query",required = true),
//    	@ApiImplicitParam(name="beginTime",value = "用户名",paramType = "query"),
//    	@ApiImplicitParam(name="endTime",value = "状态",paramType = "query"),
//    	@ApiImplicitParam(name="status",value = "角色id",paramType = "query"),
//      })
	@GetMapping("pageQuery")
	public Message pageQuery(int pageIndex, int pageSize, String username ,String status, Long roleId) {
		List<BaseUserExtend> baseuser= baseuserService.pageQuery(pageIndex,pageSize, username ,status,roleId);
		return MessageUtil.success(baseuser);
	}
}
